﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LigerMVC.Common;

namespace LigerMVC.IDataAccess
{
    using System.Linq.Expressions; 

    public partial interface IDataAccess<T>  
        where T : class
    { 
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(T entity);
 
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Insert(T entity);


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);


        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Exist(Expression<Func<T, bool>> exp);

         

        /// <summary>
        /// 获取单个实体对象 (Linq表达式)
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        T Find(Expression<Func<T, bool>> exp);
          
        /// <summary>
        /// 获取全部
        /// </summary>
        /// <returns></returns>
        List<T> FindAll();

        /// <summary>
        /// 获取数据  (规则)
        /// </summary>
        /// <returns></returns>
        List<T> GetList(FilterGroup filter);

        /// <summary>
        /// 获取数据  (Linq表达式)
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        List<T> GetList(Expression<Func<T, bool>> exp); 

        /// <summary>
        /// 获取分页数据 (规则)
        /// </summary>
        /// <returns></returns>
        PagedData<T> GetPaged(QueryDescriptor descriptor);

        /// <summary>
        /// Linq 接口
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Query();

        /// <summary>
        /// Sql Query 接口
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parms"></param>
        /// <returns></returns>
        IEnumerable<T> SqlQuery(string sql, params object[] parms);
    
    }
}